﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility; 

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RMVender

        public List<tb_RMVender> GetAllRMVender()
        {

            var query = (from obj in this.tb_RMVenders
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }

        public tb_RMVender GetRMVenderById(int id)
        {
            return this.tb_RMVenders.SingleOrDefault(tb_RMVender => tb_RMVender.Id == id);
        }

        public void CreateRMVender(tb_RMVender entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RMVenders.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyRMVender(tb_RMVender entity)
        {
            tb_RMVender instance = this.tb_RMVenders.SingleOrDefault(p => p.Id == entity.Id);

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;
            instance.Name = entity.Name; 
            instance.Address = entity.Address;
            instance.BankInformation = entity.BankInformation;
            instance.Description = entity.Description;
            instance.Fax = entity.Fax;
            instance.Tel1 = entity.Tel1;
            instance.Tel2 = entity.Tel2;
            instance.URL = entity.URL;
            instance.LinkMan = entity.LinkMan;

            this.SubmitChanges();
        }
        public void DeleteRMVender(tb_RMVender entity)
        {
            tb_RMVender deleteEntity = tb_RMVenders.SingleOrDefault(p => p.Id == entity.Id);
            tb_RMVenders.DeleteOnSubmit(deleteEntity);
            this.SubmitChanges();
        }

        #endregion

    }
}
